"""
课程管理模块信号处理
"""
from django.db.models.signals import post_save, post_delete
from django.dispatch import receiver
from django.db.models import Count, Avg
from .models import Course, CourseEnrollment, CourseResource


@receiver(post_save, sender=CourseEnrollment)
def update_course_student_count(sender, instance, created, **kwargs):
    """更新课程学生数量"""
    if created:
        course = instance.course
        course.current_students = CourseEnrollment.objects.filter(
            course=course,
            status='registered'
        ).count()
        course.save(update_fields=['current_students'])


@receiver(post_save, sender=CourseResource)
def update_resource_statistics(sender, instance, created, **kwargs):
    """更新资源统计信息"""
    if created and instance.course:
        # 这里可以添加资源统计逻辑
        pass